package com.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.health.entity.Appointment;
import com.health.entity.AppointmentSetting;
import com.health.entity.pojo.PageData;
import com.health.entity.pojo.dto.QueryAppointPhysicalDTO;
import com.health.entity.pojo.dto.QueryAppointRegisterByDoctorDTO;
import com.health.entity.pojo.dto.QueryAppointRegisterDTO;
import com.health.entity.pojo.vo.AppointPhysicalDownloadVO;
import com.health.entity.pojo.vo.AppointPhysicalVO;
import com.health.entity.pojo.vo.AppointRegisterDownloadVO;
import com.health.entity.pojo.vo.ApponitmentRegisterVO;
import com.health.mapper.AppointmentMapper;
import com.health.mapper.AppointmentSettingMapper;
import com.health.service.IAppointmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.health.service.IAppointmentSettingService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 预约表 服务实现类
 * </p>
 *
 * @author konglz
 * @since 2023-04-16
 */
@Service
public class AppointmentServiceImpl extends ServiceImpl<AppointmentMapper, Appointment> implements IAppointmentService {

    @Override
    public PageData listPageRegisterAppointInfo(Integer currentPage , Integer pageSize, QueryAppointRegisterDTO queryAppointRegisterDTO) {
        IPage<ApponitmentRegisterVO> page = new Page<>(currentPage, pageSize);
        IPage iPage = baseMapper.listPageRegisterAppointInfo((Page) page, queryAppointRegisterDTO);
        return new PageData(iPage.getTotal(), iPage.getRecords());
    }

    @Override
    public PageData listPageRegisterAppointByDoctor(QueryAppointRegisterByDoctorDTO queryAppointRegisterByDoctorDTO) {
        IPage<ApponitmentRegisterVO> page = new Page<>(queryAppointRegisterByDoctorDTO.getCurrentPage(), queryAppointRegisterByDoctorDTO.getPageSize());
        IPage iPage = baseMapper.listPageRegisterAppointByDoctor(page,queryAppointRegisterByDoctorDTO.getDoctorId(), queryAppointRegisterByDoctorDTO.getWorkTime(), queryAppointRegisterByDoctorDTO.getAppointDate());
        return new PageData(iPage.getTotal(), iPage.getRecords());
    }

    @Override
    public List<AppointRegisterDownloadVO> listPageRegisterAppointByDoctorDownlaod(QueryAppointRegisterByDoctorDTO queryAppointRegisterByDoctorDTO) {
        IPage<ApponitmentRegisterVO> page = new Page<>(queryAppointRegisterByDoctorDTO.getCurrentPage(), queryAppointRegisterByDoctorDTO.getPageSize());
        IPage iPage = baseMapper.listPageRegisterAppointByDoctor(page,queryAppointRegisterByDoctorDTO.getDoctorId(), queryAppointRegisterByDoctorDTO.getWorkTime(), queryAppointRegisterByDoctorDTO.getAppointDate());
        List<AppointRegisterDownloadVO> lists = iPage.getRecords();
        List<AppointRegisterDownloadVO> list = new ArrayList<>();
        for (Object o : lists) {
            AppointRegisterDownloadVO item = new AppointRegisterDownloadVO();
            BeanUtils.copyProperties(o, item);
            list.add(item);
        }
        return list;
    }

    @Autowired
    AppointmentMapper appointmentMapper;

    /**
     *  预约查询体检 服务实现类
     *  @author yu
     *  @since 2023-04-20
     */

    //预约查询体检 数据列表获取
    @Override
    public PageData listAllPhysicals(Integer pageNum, Integer pageSize,QueryAppointPhysicalDTO dto) {
        IPage<AppointPhysicalVO> page = new Page<>(pageNum,pageSize);
        IPage iPage = appointmentMapper.listAllPhysicals((Page)page,dto);

        return new PageData(iPage.getTotal(),iPage.getRecords());
    }

    ////预约查询体检 预约明细 基本信息
    @Override
    public List<AppointPhysicalVO> getPhysicalById(Integer id) {
        List<AppointPhysicalVO> physicalById = appointmentMapper.getPhysicalById(id);
        return physicalById;
    }

    //预约查询体检 预约明细
    @Override
    public PageData getPhysicalOrderById(Integer pageNum, Integer pageSize, Integer id) {
        IPage<AppointPhysicalVO> page = new Page<>(pageNum,pageSize);
        IPage<AppointPhysicalVO> iPage = appointmentMapper.getPhysicalOrderById((Page)page, id);
        return new PageData(iPage.getTotal(),iPage.getRecords());
    }

    //导出数据
    @Override
    public List<AppointPhysicalDownloadVO> listPhysicalDownload(Integer id) {
        IPage<AppointPhysicalVO> page = new Page<>();
        IPage iPage = appointmentMapper.getPhysicalOrderById((Page) page, id);
        List<AppointPhysicalDownloadVO> lists = iPage.getRecords();
        List<AppointPhysicalDownloadVO> list = new ArrayList<>();
        for (Object o : lists) {
            AppointPhysicalDownloadVO items = new AppointPhysicalDownloadVO();
            BeanUtils.copyProperties(o,items);
            list.add(items);
        }
        return list;
    }

}
